﻿using Base.Core20;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Winservice.demo.Business;

namespace Winservice.demo
{
    partial class Winservice : ServiceBase
    {

        public Winservice()
        {
            string[] S = { "老板" };
            InitializeComponent();

                OnStart(S);
            



        }

        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。

            Logger.Error("【】出错，原因：" + "测试");
            try
            {
                ThreadWithState tws = new ThreadWithState();
                ////方法一：调用线程执行方法，在方法中实现死循环，每个循环Sleep设定时间
                //Thread thread = new Thread(new ThreadStart(tws.ThreadProcessing));
                //thread.Start();

                var SendFeedBackTask = Task.Factory.StartNew(() => { tws.ThreadProcessing(); });

            }
            catch (Exception ce)
            {
                Logger2.CreateInstance().Write("A5_TaskSer_Error"
                , MethodBase.GetCurrentMethod()
                , ce, string.Format("服务在开始运行的时候就发送了异常！停止时间({0})", DateTime.Now));

                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Finished by {0}", DateTime.Now);
            }
            Console.ReadKey();




        }

        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
        }
    }
}
